//
//  FPViewController.m
//  FPIJKMediaFramework
//
//  Created by YannChee on 11/02/2021.
//  Copyright (c) 2021 YannChee. All rights reserved.
//

#import "FPViewController.h"
#import <IJKMediaFramework/IJKMediaFramework.h>

@interface FPViewController ()
@property(nonatomic, strong) IJKFFMoviePlayerController *player;
@property(nonatomic, strong) UIView *playerView;
@end

@implementation FPViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [super viewDidLoad];
       
        self.view.backgroundColor = UIColor.yellowColor;
        
        NSURL *url = [NSURL URLWithString:@"http://vjs.zencdn.net/v/oceans.mp4"];
    #ifdef DEBUG
        [IJKFFMoviePlayerController setLogReport:YES];
        [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG];
    #else
        [IJKFFMoviePlayerController setLogReport:NO];
        [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_INFO];
    #endif

        [IJKFFMoviePlayerController checkIfFFmpegVersionMatch:YES];
        

        IJKFFOptions *options = [IJKFFOptions optionsByDefault];

        self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options];
        self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        self.player.view.frame = self.view.bounds;
        self.player.view.backgroundColor = [UIColor redColor];
        self.player.scalingMode = IJKMPMovieScalingModeAspectFit;
        self.player.shouldAutoplay = YES;

        self.view.autoresizesSubviews = YES;
        [self.view addSubview:self.player.view];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.player prepareToPlay];
    });
      
}

@end
